package cn.bigcontainer.alt.sys.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.bigcontainer.alt.sys.service.SysXiaoxiService;

/**
 * 消息的Service接口实现类.
 *
 * @author jiaod
 * @date 2020-03-24
 */
@Service
@Transactional
public class SysXiaoxiServiceImpl implements SysXiaoxiService {

	/*
	@Resource
	private SysXiaoxiMapper sysXiaoxiMapper;

	@Resource
	private MCrudService crudService;
	
	@Override
	public MViewDto loadReplyForm(String appId, String selectedIds, Map<String, Object> req) {
		MViewDto createForm = crudService.loadCreateForm(appId, null, req);
		// 被回复的消息
		SysXiaoxi sysXiaoxi = sysXiaoxiMapper.selectById(selectedIds);
		setReplyForm(createForm, sysXiaoxi);
		return createForm;
	}

	private void setReplyForm(MViewDto createForm, SysXiaoxi sysXiaoxi) {
		// 设置回复消息ID
		createForm.getProperty("cx_sys_xiaoxi_mhfxx0_id").setValue(sysXiaoxi.getMid());
		// 设置原始消息ID
		createForm.getProperty("cx_sys_xiaoxi_mysxx0_id").setValue(sysXiaoxi.getMysxx0Id() == null ? sysXiaoxi.getMid() : sysXiaoxi.getMysxx0Id());
		// 设置标题
		createForm.getProperty("cx_sys_xiaoxi_mbt").setValue("回复：" + sysXiaoxi.getMbt());
		// 将sysXiaoxi的发送人设置为本次回复的接收人
		createForm.getProperty("cx_sys_xiaoxi_r20").setValue("sys_user:" + sysXiaoxi.getMfsr0Id());
	}

	@Resource
	private SysXiaoxiCsrMapper sysXiaoxiCsrMapper;
	
	@Resource
	private SysXiaoxiJsrMapper sysXiaoxiJsrMapper;
	
	@Override
	public MViewDto loadReplyAllForm(String appId, String selectedIds, Map<String, Object> req) {
		MViewDto createForm = crudService.loadCreateForm(appId, null, req);
		// 被回复的消息
		SysXiaoxi sysXiaoxi = sysXiaoxiMapper.selectById(selectedIds);
		setReplyForm(createForm, sysXiaoxi);
		// 将sysXiaoxi的抄送人设置为本次回复的抄送人
		List<SysXiaoxiCsr> csrs = sysXiaoxiCsrMapper.selectList(new QueryWrapper<SysXiaoxiCsr>().eq("mxiaoxi0_id", sysXiaoxi.getMid()));
		if (csrs.size() > 0) {
			List<String> csrList = new ArrayList<String>();
			for (int i = 0; i < csrs.size(); i++) {
				SysXiaoxiCsr csr = csrs.get(i);
				csrList.add(csr.getRelatedObjectId() + ":" + csr.getInverseProperty0Id());
			}
			createForm.getProperty("cx_sys_xiaoxi_r30").setValue(WoKit.join(csrList));
		}
		// 将sysXiaoxi的发送人和接收人设置为本次回复的接收人
		List<SysXiaoxiJsr> jsrs = sysXiaoxiJsrMapper.selectList(new QueryWrapper<SysXiaoxiJsr>().eq("mxiaoxi0_id", sysXiaoxi.getMid()));
		List<String> jsrList = new ArrayList<String>();
		jsrList.add("sys_user:" + sysXiaoxi.getMfsr0Id());
		for (int i = 0; i < jsrs.size(); i++) {
			SysXiaoxiJsr jsr = jsrs.get(i);
			String jsrValueString = jsr.getRelatedObjectId() + ":" + jsr.getInverseProperty0Id();
			if (jsrList.contains(jsrValueString)) {
				continue;
			}
			jsrList.add(jsrValueString);
		}
		createForm.getProperty("cx_sys_xiaoxi_r20").setValue(WoKit.join(jsrList));
		return createForm;
	}
	*/
}
